package com.demo.controller;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/qldemo")
public class QlexpressController {

    @GetMapping("/execute")
    public String execute() {
        ExpressRunner runner = new ExpressRunner();
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a",1);
        context.put("b",2);
        context.put("c",3);
        String express = "a+b*c";
        Object r = null;
        try {
            r = runner.execute(express, context, null, true, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "测试QLExpress，运算结果：" + r;
    }

    @GetMapping("/exec")
    public String exec() {
        ExpressRunner runner = new ExpressRunner();
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a",1);
        context.put("b",2);
        context.put("c",3);
        String express = "a > b";
        Object r = null;
        try {
            r = runner.execute(express, context, null, true, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "测试QLExpress，a > b结果：" + r;
    }

}
